<template>
  <div class="collapse-wrap">
    <div class="header">
      <div class="title">
        <slot name="ico" />
        <b>{{ title }}</b>
      </div>
      <el-icon
        class="ico-wrap"
        @click="isOpen = isOpen ? false : true"
      >
        <arrow-up
          :class="{
            ico: true,
            down: !isOpen ? true : false,
          }"
        />
      </el-icon>
    </div>
    <div class="content">
      <div v-show="isOpen">
        <slot />
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from 'vue'
export default defineComponent({
  name: 'CollapseCpt',
  props: {
    title: {
      type: String,
      default: '' // 默认值
    },
    open: {
      type: Boolean,
      default: false // 默认值
    }
  },
  setup (props) {
    const isOpen = ref(false)
    onMounted(() => {
      isOpen.value = Boolean(props.open)
    })

    return { isOpen }
  }
})
</script>

<style lang="scss" scoped>
@import '@/assets/css/constant.scss';
@import '@/assets/css/mixin.scss';

.collapse-wrap {
  overflow: hidden;
  margin-top: 20px;
  padding: 10px;
  border: 1px solid $theme-color4;
  border-radius: 5px;
  background: $theme-color6;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .title {
      display: flex;
      margin: 8px 0;
      align-items: center;
    }
    .ico-wrap {
      width: 20px;
      height: 20px;
      transform: translateY(2px);
      cursor: pointer;
      .ico {
        transition: all 0.3s ease;
        transform: rotate(0deg);
        &.down {
          transform: rotate(180deg);
        }
      }
    }
  }
  .content {
    transition: height 0.5s ease;
    height: 100%;
    .item {
      margin-bottom: 4px;
    }
  }
}
</style>
